home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / is_con10.zip / REDIRECT.MSG < prev    next >
Text File  |  1993-05-04  |  4KB  |  94 lines

  1.   From: Jerry Coffin
  2.     To: All                Date: 15 Dec 91  12:15:04
  3.   Subj: file redirection
  4.   Conf: `PC Assembly Language'
  5.  
  6.     A while back, someone posted a message about whether you would
  7. accurately detect redirection of standard input and/or output by testing
  8. whether file handle(s) 0 & 1 were equal to file handle 3.  I've done a
  9. little testing and found that if you redirect standard error within a
  10. program, ( freopen() it, for instance. ) and spawn a child program, the
  11. child's file handle 3 will indeed be changed, and handles 0 and 1 will
  12. not equal it unless they have redirected to the same file.  It would
  13. appear, therefore, that accurately determining whether input or output
  14. has been redirected requires using DOS function 52h to find the
  15. system file table, and tracking through it to find whether the file
  16. associated with the handle in question is actually connected to a file
  17. named CON.  ( PLEASE prove me wrong on this, though. )
  18.     Later,
  19.     Jerry.
  20.  
  21.   From: Robert Mashlan
  22.     To: Jerry Coffin            Date: 16 Dec 91  22:48:15
  23.   Subj: file redirection
  24.   Conf: `PC Assembly Language'
  25.  
  26.  > appear, therefore, that accurately determining whether
  27.  > input or output has been redirected requires using DOS
  28.  > function 52h to find the system file table, and
  29.  > tracking through it to find whether the file
  30.  > associated with the handle in question is actually
  31.  > connected to a file named CON.  ( PLEASE prove me
  32.  > wrong on this, though. )
  33.  
  34. Instead of using an undocumented function, why not use a documented one?  Int
  35. 21h, func 44h, subfunc 0, should give you the information needed.
  36.  
  37. Robert
  38.  
  39.   From: Ed Beroset
  40.     To: Jerry Coffin            Date: 17 Dec 91  08:55:00
  41.   Subj: file redirection
  42.   Conf: `PC Assembly Language'
  43.  
  44.  JC>    A while back, someone posted a message about whether you would
  45.  JC> accurately detect redirection of standard input and/or output by testing
  46.  JC> whether file handle(s) 0 & 1 were equal to file handle 3.
  47.  
  48. There were several messages; I posted one of them.
  49.  
  50.  JC> I've done a
  51.  JC> little testing and found that if you redirect standard error within a
  52.  JC> program, ( freopen() it, for instance. ) and spawn a child program, the
  53.  JC> child's file handle 3 will indeed be changed, and handles 0 and 1 will
  54.  JC> not equal it unless they have redirected to the same file.
  55.  
  56. This is quite correct.  The program I posted was only designed to check for
  57. command line redirection, and will not detect such subterfuge as you describe.
  58.  
  59.  JC> It would
  60.  JC> appear, therefore, that accurately determining whether input or output
  61.  JC> has been redirected requires using DOS function 52h to find the
  62.  JC> system file table, and tracking through it to find whether the file
  63.  JC> associated with the handle in question is actually connected to a file
  64.  JC> named CON.  ( PLEASE prove me wrong on this, though. )
  65.  
  66. I hadn't considered a program quite this thorough, but it sounds workable.  The
  67. only problem that I see with this strategem is that the console device itself
  68. may legitimately have been redirected (e.g. CTTY COM1) to a terminal or some
  69. other device.  Let us all know if you work it all out -- sounds interesting!
  70.  
  71. -> Ed <-
  72.  
  73.   From: Bob Jarvis
  74.     To: Jerry Coffin            Date: 17 Dec 91  21:53:34
  75.   Subj: file redirection
  76.   Conf: `PC Assembly Language'
  77.  
  78. In a message of <15 Dec 91  12:15:04>, Jerry Coffin (1:128/60) writes:
  79.  >not equal it unless they have redirected to the same file.  It would
  80.  >appear, therefore, that accurately determining whether input or output
  81.  >has been redirected requires using DOS function 52h to find the
  82.  >system file table, and tracking through it to find whether the file
  83.  >associated with the handle in question is actually connected to a file
  84.  >named CON.  ( PLEASE prove me wrong on this, though. )
  85.  
  86. Perhaps the following code will help:
  87.  
  88. [extracted to isconsol.c]
  89.  
  90. Hope this helps.
  91.  
  92. --- msged 1.99S ZTC
  93.  * Origin: Point of No Return - Westlake OH  (1:157/200.26)
  94.